<template>
  <div class="process-obstruct">
    <el-table :data="tableData"
              border
              :fit="true"
              style="width: 100%">
      <el-table-column label="房屋id"
                       prop="id">
      </el-table-column>
      <el-table-column label="地址"
                       prop="address">
      </el-table-column>
      <el-table-column label="报障日期"
                       prop="date">
      </el-table-column>
      <el-table-column label="租赁人"
                       prop="name">
      </el-table-column>
      <el-table-column label="报障内容"
                       prop="detail">
      </el-table-column>
      <el-table-column label="状态"
                       prop="status">
      </el-table-column>
      <el-table-column label="操作" v-if="this.role==='admin'">
        <template slot-scope="scope">
          <el-button size="mini"
                     type="primary"
                     @click="edit(scope.$index, scope.row)">处理</el-button>
          <el-button size="mini"
                     type="danger"
                     @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-box">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page="pagination.currentPage"
        :page-size="pagination.pageSize"
        layout="total, prev, pager, next"
        :total="pagination.total">
      </el-pagination>
    </div>
  </div>
</template>
<script lang="js">
import axios from "axios";

export default {
  name: 'processobstruct',
  data(){
    return {
      tableData: [],
        role: '',
      pagination: {//分页相关模型数据
        currentPage: 1,//当前页码
        pageSize: 10,//每页显示的记录数
        total: 0,//总记录数
        type:"",
        name:"",
        description:"",
      }
    }
  },
  created(){
    this.role = this.$store.state.userInfo.role;
    this.getAll();
  },
  methods: {
    getAll: function (){
      axios.get("/wrong/"+this.pagination.currentPage+"/1").then((res)=>{
        if (res.data.code === 1){
          this.tableData = res.data.data.records
          this.pagination.currentPage = res.data.data.current
          this.pagination.total = res.data.data.total
          this.pagination.pageSize = res.data.data.size
        }
      })
    },
    edit(index, row) {
        //  访问接口

        this.$message({
          message: '已经处理',
          type: 'success'
        });
      },
      handleDelete(index, row) {
          this.$confirm('确定要删除吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'error'
        }).then(() => {
          // 访问接口
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消成功'
          });
        });
      },
    //切换页码
    handleCurrentChange(currentPage) {
      this.pagination.currentPage = currentPage;
      this.getAll();
    },
    }
}
</script>
<style lang="scss" scoped>
</style>
